package com.ubis.ibms.plugin.dialogs;

import org.eclipse.jface.dialogs.Dialog;
import org.eclipse.jface.dialogs.IDialogConstants;
import org.eclipse.jface.viewers.ArrayContentProvider;
import org.eclipse.jface.viewers.ComboViewer;
import org.eclipse.jface.viewers.LabelProvider;
import org.eclipse.nebula.widgets.calendarcombo.CalendarCombo;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.MouseAdapter;
import org.eclipse.swt.events.MouseEvent;
import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Combo;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Text;

public class WorkerAddDialog extends Dialog {
	
	//姓名
	private Text nameText;
	//性别
	private Combo genderCombo;
	//部门
	private ComboViewer depComboViewer;
	private Combo depCombo;
	//职务
	private ComboViewer posComboViewer;
	private Combo posCombo;
	//联系电话
	private Text telText;
	//入职时间
	private CalendarCombo entryCombo;
	//提交
	private Button okButton;
	//清空
	private Button clearButton;
	
	private Composite container;
		
	/**
	 * Create the dialog.
	 * @param parentShell
	 */
	public WorkerAddDialog(Shell parentShell) {
		super(parentShell);
	}

	/**
	 * Create contents of the dialog.
	 * @param parent
	 */
	@Override
	protected Control createDialogArea(Composite parent) {
		container = (Composite) super.createDialogArea(parent);
		GridLayout layout = new GridLayout(3, false);
		layout.marginWidth = 10;
		layout.marginHeight = 10;
		container.setLayout(layout);
		
		//姓名
		Label nameLabel = new Label(container, SWT.RIGHT);
		nameLabel.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1));
		nameLabel.setText("姓名：");
		nameText = new Text(container, SWT.BORDER);
		nameText.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 2, 1));
		
		// 性别
		Label genderLabel = new Label(container, SWT.RIGHT);
		genderLabel.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false,
				1, 1));
		genderLabel.setText("性别：");
		genderCombo = new Combo(container, SWT.NONE);
		genderCombo.setItems(new String[] {"男", "女"});
		genderCombo.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false, 1, 1));
		new Label(container, SWT.NONE);
		
		//联系电话
		Label telLabel = new Label(container, SWT.RIGHT);
		telLabel.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1));
		telLabel.setText("联系电话：");
		telText = new Text(container, SWT.BORDER);
		telText.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false, 2, 1));
		
		// 部门
		Label depLabel = new Label(container, SWT.RIGHT);
		depLabel.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false,
				false, 1, 1));
		depLabel.setText("部门：");
		depComboViewer = new ComboViewer(container, SWT.READ_ONLY);
		depCombo = depComboViewer.getCombo();
		depCombo.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false,
				false, 1, 1));
		depComboViewer.setContentProvider(ArrayContentProvider
				.getInstance());
		depComboViewer.setLabelProvider(new LabelProvider() {
			@Override
			public String getText(Object element) {
				//TODO 得到部门text
//						if (element instanceof Building) {
//							Building building = (Building) element;
//							return building.getEms_name();
//						}
				return super.getText(element);
			}
		});
		// TODO 获取部门数据
		new Label(container, SWT.NONE);
		
		// 职务
		Label posLabel = new Label(container, SWT.RIGHT);
		posLabel.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false,
				false, 1, 1));
		posLabel.setText("职务：");
		posComboViewer = new ComboViewer(container, SWT.READ_ONLY);
		posCombo = posComboViewer.getCombo();
		posCombo.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false,
				false, 1, 1));
		posComboViewer.setContentProvider(ArrayContentProvider
				.getInstance());
		posComboViewer.setLabelProvider(new LabelProvider() {
			@Override
			public String getText(Object element) {
				//TODO 得到职务text
				return super.getText(element);
			}
		});
		// TODO 获取职务数据
		new Label(container, SWT.NONE);
		
		// 入职时间
		Label entryLabel = new Label(container, SWT.RIGHT);
		entryLabel.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER,
				false, false, 1, 1));
		entryLabel.setText("入职时间：");
		entryCombo = new CalendarCombo(container, SWT.BORDER);
		entryCombo.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false,
				false, 1, 1));
		
		return container;
	}

	/**
	 * Create contents of the button bar.
	 * @param parent
	 */
	@Override
	protected void createButtonsForButtonBar(Composite parent) {
		parent.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true,
				false, 1, 1));
		parent.setLayout(new GridLayout(2, false));
		okButton = createButton(parent, IDialogConstants.CLIENT_ID, "添加",
				false);
		okButton.setLayoutData(new GridData(SWT.CENTER, SWT.CENTER, true,
				false, 1, 1));
		okButton.addMouseListener(new MouseAdapter() {
			public void mouseUp(MouseEvent e) {
				// 点击添加时
			}
		});
		clearButton = createButton(parent, IDialogConstants.CLIENT_ID,
				"清空", false);
		clearButton.setLayoutData(new GridData(SWT.CENTER, SWT.CENTER, true,
				false, 1, 1));
		clearButton.addMouseListener(new MouseAdapter() {
			public void mouseUp(MouseEvent e) {
				// 点击清空时
			}
		});
	}

	/**
	 * Return the initial size of the dialog.
	 */
	@Override
	protected Point getInitialSize() {
		return new Point(300, 300);
	}

	@Override
	protected void configureShell(Shell newShell) {
		super.configureShell(newShell);
		newShell.setText("员工登记");
	}

}
